app.service('areaService', ['$http', '$q', 'utilService', function ($http, $q, utilService) {
    //获取可用的省份列表下拉框（未设置区县级代理区域的省份）
    this.getAvailableProvinces = function ($scope) {
        var deferred = $q.defer();
        utilService.get({
            url: $scope.app.domainAgent + 'manage/agentArea/getAvailableProvinces'
        }).then(function (response) {
            deferred.resolve(response.data);
        }, function (e) {
            console.error(e);
            deferred.reject("连接服务器出错");
        });
        return deferred.promise;
    }

    //根据省级id获取可用的城市列表下拉框（未设置区县级代理区域的城市）
    this.getAvailableCitys = function ($scope) {
        var deferred = $q.defer();
        utilService.get({
            url: $scope.app.domainAgent + 'manage/agentArea/getAvailableCitys',
            params: {parentId: $scope.agentArea.provinceId}
        }).then(function (response) {
            deferred.resolve(response.data);
        }, function (e) {
            console.error(e);
            deferred.reject("连接服务器出错");
        });
        return deferred.promise;
    }

    //根据省级id获取可用的城市列表下拉框（未设置区县级代理区域的城市）
    this.getAvailableDistricts = function ($scope) {
        var deferred = $q.defer();
        utilService.get({
            url: $scope.app.domainAgent + 'manage/agentArea/getAvailableDistricts',
            params: {parentId: $scope.agentArea.cityId}
        }).then(function (response) {
            deferred.resolve(response.data);
        }, function (e) {
            console.error(e);
            deferred.reject("连接服务器出错");
        });
        return deferred.promise;
    }
}]);